﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Infusion.Silverlight.Controls.OpenOfficeXML.WordProcessing
{
    #region : ExtendedPropertiesPart :
    public class ExtendedPropertiesPart : OpenXmlPart
    {
        private string applicationName;
        private AppVersion appVersion;
        private int characters;
        private int charactersWithSpaces;
        private string company;
        private DocumentSecurity docSecurity;
        private int lines;
        private int pages;
        private int paragraphs;
        private bool scaleCrop;
        private string template;
        private int totalTime;
        private int words;

        public override string ContentType
        {
            get
            {
                return "application/vnd.openxmlformats-officedocument.extended-properties+xml";
            }
        }

        public override string RelationshipType
        {
            get
            {
                return "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties";
            }
        }

        protected internal override string TargetName
        {
            get
            {
                return "app";
            }
        }

        protected internal override string TargetPath
        {
            get
            {
                return "docProps";
            }
        }
    }
    #endregion

    #region : AppVersion :
    public class AppVersion
    {
        #region Class Variables...
        private int major;
        private int minor;
        #endregion

        #region Constructor(s)...
        #region AppVersion()
        public AppVersion() : this(1, 0)
        {
        }
        #endregion

        #region AppVersion(string appVersion)
        public AppVersion(string appVersion)
        {
            int periodPos = appVersion.IndexOf(".");

            major = 1;
            int.TryParse(appVersion.Substring(0, periodPos == -1 ? appVersion.Length : periodPos), out major);

            minor = 0;
            if (periodPos > -1)
                int.TryParse(appVersion.Substring(periodPos + 1), out minor);
        }
        #endregion

        #region AppVersion(int major, int minor)
        public AppVersion(int major, int minor)
        {
            this.major = major;
            this.minor = minor;
        }
        #endregion
        #endregion

        #region Methods...
        #region ToString
        public override string ToString()
        {
            return string.Format("{0:00}.{1:0000}", major, minor);
        }
        #endregion
        #endregion

        #region Properties...
        #region Major
        public int Major
        {
            get { return major; }
            set
            {
                if (value > 99)
                    throw new ArgumentOutOfRangeException("Major version number must be less than 100");

                major = value;
            }
        }
        #endregion

        #region Minor
        public int Minor
        {
            get { return minor; }
            set
            {
                if (value > 9999)
                    throw new ArgumentOutOfRangeException("Minor version number must be less than 10000");

                minor = value;
            }
        }
        #endregion
        #endregion
    }
    #endregion
}